Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
db.collection("articles").add results in ".default.collection is not a function"

Essentially I want to add a collection called "articles" with the following actors and store it in firebase.

I followed the doc for uploading files to firebase. I was reading the doc for adding data to firebase but it was a bit confusing and not sure how to implement it.

index.js (to view the other top half, here)

...
() => {
   getDownloadURL(upload.snapshot.ref).then((downloadURL) => {
    db.collection("articles").add({
      actor: {
        description: payload.user.email,
        title: payload.user.displayName,
        date: payload.timestamp,
        image: payload.user.photoURL,
        },
        video: payload.video,
        sharedImg: downloadURL,
        comments: 0,
        description: payload.description,
       });
   });
}

However, whenever I run this code, I get "Unhandled Rejection (TypeError): firebase__WEBPACK_IMPORTED_MODULE_0_.default.collection is not a function."

firebase.js

import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider } from 'firebase/auth';
import { getStorage } from "firebase/storage";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
...
}

const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);
const auth = getAuth();
const provider = new GoogleAuthProvider();
const storage = getStorage(firebaseApp);
  
export { auth, provider, storage };
export default db;

Any advise as to what is going wrong? Thanks!

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Same as on your previous question, since you're using the v9 syntax to import specific functions, you can no longer call methods on db or a CollectionReference.

The equivalent of your snippet in the v9 modular syntax is:

const collectionRef = collection(db, "articles")
addDoc(collectionRef, { ... })

I strongly recommend that you spend some time in the Firebase documentation on writing data and in the upgrade guide to get familiar with how the syntax in your existing code maps to the new syntax.


If you don't want to upgrade your code, you can also consider using the compat paths of the v9 SDKs.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda